package org.example.Server.controller.resource;

import lombok.extern.slf4j.Slf4j;
import org.example.Server.model.resource.VideoDTO;
import org.example.Server.model.resource.VideoVO;
import org.example.Server.service.resource.ResourceService;
import org.example.Server.utils.ResultAPI;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("/youxich/resource/personal/video")
@Slf4j
public class VideoPersonalController {
    @Autowired
    ResourceService resourceService;

    /**
     * 获取审核类型的教师资源————视频
     *
     * @param tech_id
     * @return
     */
    @GetMapping
    public ResultAPI getvideo(@RequestParam Integer tech_id, @RequestParam(required = false) Integer ispass) {
        return resourceService.getVideoByTechid(tech_id, ispass);
    }

    /**
     * 教师添加视频资源
     *
     * @param tech_id
     * @param file
     * @return
     */
    @PostMapping
    public ResultAPI addvideo(Integer tech_id, MultipartFile file) {
        try {
            return resourceService.addvideo(tech_id, file);
        } catch (IOException e) {
            log.error(e.getMessage());
            return ResultAPI.error(e.getMessage());
        }
    }

    /**
     * 删除教师视频
     *
     * @param resource_id
     * @return
     */
    @DeleteMapping("/{resource_id}")
    public ResultAPI deletevideo(@PathVariable Integer resource_id) {
        return resourceService.deletevideo(resource_id);
    }

    /**
     * 更新教师端视频命名
     *
     * @param videoDTO
     * @return
     */
    @PutMapping
    public ResultAPI updatevideo(@RequestBody VideoDTO videoDTO) {
        return resourceService.updatevideo(videoDTO);
    }
}
